const app = getApp()
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputContent: ''//输入的内容
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //请求分享数据
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=wx_share&op=get_share',
      data: {},
      method: 'GET',
      dataType: 'json',
      success: res => {
        if (res.data.code == '200') {
          this.setData({
            share_default_title: res.data.datas.title,
            share_default_image_url: res.data.datas.imageUrl
          })
        }
      }
    })
    util.share();
    let self = this;
    wx.getStorage({
      key: 'key',
      success: (res) => {
        self.setData({
          member_key: res.data
        });
      }
    })
  },
  /*
   *监听手机号的输入
   */
  contentInput: function (event) {
    var self = this;
    self.setData({
      inputContent: event.detail.value
    });
  },

  /**
   * 反馈内容提交
   */
  commitContent: function () {
    let self = this;
    if (!self.data.inputContent) {
      wx.showToast({
        title: '请输入反馈的内容',
        icon: 'none'
      });
      return;
    }
    wx.showLoading({
      title: "加载中",
    })
    wx.request({
      url: app.globalData.ApiUrl + '/index.php?act=member_feedback&op=feedback_add',
      method: "POST",
      data: {
        key: self.data.member_key,
        feedback: self.data.inputContent
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data.code == 200) {
          wx.navigateBack({
            delta: 1
          });
          wx.showToast({
            title: '感谢您的宝贵意见!',
            icon: 'none'
          })
        } else {
          wx.showToast({
            title: res.data.datas.error,
            icon: 'none'
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        })
      }
    });
  },

  onShareAppMessage: function () {
    let share_key = this.data.member_key ? this.data.member_key : '';
    let share_path = '';
    if (util.getCurrentPageUrlWithArgs().indexOf("?") != -1) {
      share_path = util.getCurrentPageUrlWithArgs() + '&share_key=' + share_key;
    } else {
      share_path = util.getCurrentPageUrlWithArgs() + '?share_key=' + share_key;
    }
    return {
      title: this.data.share_default_title,
      imageUrl: this.data.share_default_image_url,
      path: share_path
    }
  }
})